package com.ljh.account.mapper;

import com.ljh.account.dao.Account;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AccountMapper {

//    @Insert("INSERT INTO accounts (username, password, email, account_type, is_active, avatar_url, created_at, updated_at) VALUES (#{username}, #{password}, #{email}, #{accountType}, #{isActive}, #{avatarUrl}, #{createdAt}, #{updatedAt})")
    @Insert("INSERT INTO accounts (username, password) VALUES (#{username}, #{password})")
    void insertAccount(Account account);

    @Select("SELECT * FROM accounts WHERE id = #{id}")
    Account getAccountById(Long id);

    @Select("SELECT * FROM accounts")
    List<Account> getAllAccounts();

//    @Update("UPDATE accounts SET username = #{username}, password = #{password}, email = #{email}, account_type = #{accountType}, is_active = #{isActive}, avatar_url = #{avatarUrl}, updated_at = #{updatedAt} WHERE id = #{id}")
//    修改用户的详情（邮箱，头像）
    @Update("UPDATE accounts SET  email = #{email}, avatar_url = #{avatarUrl} WHERE id = #{id}")
    void updateAccount(Account account);

    @Delete("DELETE FROM accounts WHERE id = #{id}")
    void deleteAccount(Long id);

    @Select("SELECT * FROM accounts WHERE username = #{username}")
    Account getAccountByUsername(String username);
}